package com.base;

public class ArrayDemo02 {
    public static void main(String[] args) {
        int[]  a = {1,2,3,4};

        // 数组作为参数
        printArray(a);

        int[] res = reverse(a);
        for (int i : res) {
            System.out.print(i + " ");
        }
    }


    //打印数组
    public  static  void printArray(int[] array){
        for (int i : array) {
            System.out.print(i +" ");
        }
        System.out.println();
    }



    // 翻转数组
    public static int[] reverse(int[] array){
        int[] result = new int[array.length];

       for(int i = 0, j = result.length -1; i< array.length && j >= 0;i++,j--){
            result[j] = array[i];
       }

        return  result;
    }

}
